package frame.options.simulation;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.URI;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import model.algorithms.embedding.EmbeddingAlgorithm;
import model.algorithms.linksMapping.LinksMappingAlgorithm;
import model.algorithms.nodesMapping.NodesMappingAlgorithm;
import model.algorithms.rounding.RoundingAlgorithm;
import model.algorithms.splitting.SplittingAlgorithm;
import model.components.networks.Network;
import model.components.networks.sdn.SdnNetwork;
import model.components.networks.virtual.VirtualNetwork;
import frame.SimulatorFrame;
import frame.networks.tables.NetworksTableTabbedPane;
import frame.networks.tables.sdn.SdnTableModel;
import frame.networks.tables.virtual.VirtualTableModel;
import frame.options.sdn.OpenSdnMenuItem;
import frame.options.simulation.create.CreateSimulationWizard;
import frame.options.simulation.create.backup.BackupDescriptor;
import frame.options.simulation.create.coordinated.CoordinatedDescriptor;
import frame.options.simulation.create.cost.CostDescriptor;
import frame.options.simulation.create.embedding.EmbeddingDescriptor;
import frame.options.simulation.create.links.LinksDescriptor;
import frame.options.simulation.create.nodes.NodesDescriptor;
import frame.options.simulation.create.rounding.RoundingDescriptor;
import frame.options.simulation.create.sdn.SdnDescriptor;
import frame.options.simulation.create.splitting.SplittingDescriptor;
import frame.options.simulation.create.virtual.VirtualDescriptor;
import frame.options.simulation.running.RunningFrame;

@SuppressWarnings("serial")
public class RunSimulationMenuItem extends JMenuItem implements ActionListener
{
	private SimulatorFrame simulatorFrame;
	public SimulatorFrame getFrame(){ return simulatorFrame; }
	public void setFrame( SimulatorFrame simulatorFrame ){ this.simulatorFrame = simulatorFrame; }
	
	public RunSimulationMenuItem( SimulatorFrame simulatorFrame )
	{
		this.setFrame( simulatorFrame );
		this.setText( "Run" );
		this.setMnemonic( KeyEvent.VK_C );
		this.setIcon( new ImageIcon( this.getClass().getResource( "/icons/create.png" ) ) );
		this.addActionListener( this );
	}

	@Override
	public void actionPerformed( ActionEvent actionEvent )
	{	
		/*try
		{
			File file = new File( new URI( "C:\Users\aureliojg\Desktop\SdnNetworks.xls" ) );
			OpenSdnMenuItem openSdnMenuItem = new OpenSdnMenuItem( null );
			List< SdnNetwork > sdnNetworks = openSdnMenuItem.openSdnNetworks( file );
		
			Simulation2 simulation = new Simulation2( sdnNetworks, null );
			this.getFrame().getSimulator().setSimulation( simulation );
			this.launchSimulation( simulation );
		}
		catch( NullPointerException exception )
		{
			JOptionPane.showMessageDialog( this.getFrame().getNetworksPanel(), "Incorrect file", "Filer error", 1 );
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public void launchSimulation( Simulation simulation )
	{
		Point topLeft = this.getFrame().getNetworksPanel().getLocationOnScreen();
		Dimension parentSize = this.getFrame().getNetworksPanel().getSize();
		RunningFrame frameRunning = new RunningFrame( simulation, this.getFrame() );
		frameRunning.setLocation( topLeft.x + ( parentSize.width  / 2 ) - ( frameRunning.getPreferredSize().width  / 2 ), topLeft.y + ( parentSize.height / 2 ) - ( frameRunning.getPreferredSize().height / 2 ) );
		frameRunning.pack();
		frameRunning.setVisible( true );
		frameRunning.getRunningSwingWorker().execute();
	}
	
}
